<template>
  <div>
    <div class="my-header">
      <img src="http://liufusong.top:8080/img/profile/bg.png" alt />
      <div class="my-info">
        <div class="head-portrait">
          <img src="http://liufusong.top:8080/img/profile/avatar.png" alt />
        </div>
        <div class="my-name">
          <span>{{ username ? username : '游客' }}</span>
        </div>
        <div class="van-link">
          <router-link class="button" to="/login" v-if="!username">去登录</router-link>
          <button class="button" v-else @click="showDialog">退出</button>
        </div>
        <div class="my-txt" v-if="username">
          编辑个人资料
          <van-icon name="play" color="#999" size="12px" />
        </div>
      </div>
    </div>
    <div class="my-van">
      <van-grid :column-num="3" :border="false" :icon-size="20" class="van-grid">
        <van-grid-item to='/collect' icon="star-o" text="我的收藏" />
        <van-grid-item to="/mylease" icon="wap-home-o" text="我的出租" />
        <van-grid-item icon="underway-o" text="看房记录" />
        <van-grid-item icon="debit-pay" text="成为房主" />
        <van-grid-item icon="contact" text="个人资料" />
        <van-grid-item icon="service-o" text="联系我们" />
      </van-grid>
    </div>
    <div class="my-ad">
      <img src="http://liufusong.top:8080/img/profile/join.png" alt />
    </div>
  </div>
</template>

<script>
export default {
  name: 'HaokezfMy',

  data () {
    return {
      username: ''
    }
  },
  created () {
    this.username = localStorage.getItem('MY-HK-username')
  },

  mounted () {},

  methods: {
    showDialog () {
      this.$dialog
        .confirm({
          width: '270px',
          title: '提示',
          message: '是否确定退出?',
          confirmButtonText: '退出',
          confirmButtonColor: '#108ee9'
        })
        .then(() => {
          // on confirm
          localStorage.removeItem('MY-HK-TOKEN')
          localStorage.removeItem('MY-HK-username')
          // 刷新页面
          this.$router.go(0)
          this.$toast.loading({
            message: '加载中...',
            forbidClick: true
          })
        })
        .catch(() => {
          // on cancel
        })
    }
  }
}
</script>

<style lang="less" scoped>
.my-header {
  position: relative;
  height: 300px;
  img {
    width: 100%;
  }
  .my-info {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 318.91px;
    height: 165px;
    margin: 0 auto;
    background-color: #fff;
    box-shadow: 0 0 10px 3px #ddd;
    z-index: 9;
    .head-portrait {
      position: absolute;
      top: 0;
      left: 50%;
      width: 70px;
      height: 70px;
      transform: translate(-50%, -50%);
      border: 5px solid #f5f5f5;
      border-radius: 50%;
      box-shadow: 0 2px 2px #bdbdbd;
      box-sizing: border-box;
      img {
        width: 100%;
      }
    }
    .my-name {
      position: absolute;
      top: 55px;
      left: 50%;
      font-size: 13px;
      color: #333;
      transform: translateX(-50%);
    }
    .van-link {
      position: absolute;
      top: 90px;
      left: 50%;
      width: 69px;
      height: 30px;
      border-radius: 5px;
      font-size: 13px;
      transform: translateX(-50%);
      background-color: #21b97a;
      .button {
        display: inline-block;
        width: 100%;
        height: 100%;
        text-align: center;
        line-height: 30px;
        background-color: #21b97a;
        color: #fff;
        border-radius: 5px;
        border: none;
      }
    }
    .my-txt {
      position: absolute;
      bottom: 15px;
      left: 0;
      width: 100%;
      text-align: center;
      color: #999;
      font-size: 12px;
    }
  }
}
.my-van {
  height: 190px;
  .van-grid {
    height: 100%;
  }
}
.my-ad {
  width: 345px;
  height: 85px;
  margin: 10px auto;
  img {
    width: 100%;
  }
}
</style>
